package com.hnas.eastsquare.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.StringUtil;
import com.hnas.eastsquare.orm.SedimentaryBalance;

@Component("sedimentaryBalanceDao")
public class SedimentaryBalanceDaoImpl extends BaseDaoImpl<SedimentaryBalance> implements SedimentaryBalanceDao{

	public SedimentaryBalanceDaoImpl() {
		super(SedimentaryBalance.class);
	}

	@Override
	public SedimentaryBalance saveOrUpdate(SedimentaryBalance vo) throws Exception {
		if(vo == null||StringUtil.isEmpty(vo.getId())) return null;
		SedimentaryBalance entity = this.entityManager.find(SedimentaryBalance.class, vo.getId());
		if(entity == null){
			this.entityManager.persist(vo);
		}else{
			this.entityManager.merge(vo);
		}
		return vo;
	}

	@Override
	public SedimentaryBalance findSingleResult() {
		String sql = "from SedimentaryBalance";
		List<SedimentaryBalance> findByQuery = this.findByQuery(sql);
		if(findByQuery != null && findByQuery.size() > 0 ){
			return findByQuery.get(0);
		}
		return null;
	}

}
